//
//  GSSubscribeViewController_Add_Topic_Cell.m
//  GameSky
//
//  Created by lanou on 16/1/11.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSSubscribeViewController_Add_Topic_Cell.h"

@implementation GSSubscribeViewController_Add_Topic_Cell
#pragma mark----------------自定义初始化-------------------
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 夜间模式
        self.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
// 图片
        _imageV = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, 80, 55)]
        ;
        //_imageV.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_imageV];
// 标题title
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(96, 8, 160, 36)];
        //_titleLabel.backgroundColor = [UIColor purpleColor];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.numberOfLines = -1;
        [self.contentView addSubview:_titleLabel];
// 订阅人数
        _subscibeCount = [[UILabel alloc] initWithFrame:CGRectMake(96, 44, 132, 20)];
      //_subscibeCount.backgroundColor = [UIColor yellowColor];
        [self.contentView addSubview:_subscibeCount];
// 订阅按钮
        _subscibeButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _subscibeButton.frame = CGRectMake(kScreenWidth - 30 - 53, 21, 53, 29);
        [_subscibeButton setTitle:@"订阅" forState:(UIControlStateNormal)];
        [_subscibeButton setTitle:@"退订" forState:(UIControlStateSelected)];
        _subscibeButton.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_subscibeButton];
    }
    return self;
}
#pragma mark-----------------重写setter方法----------------
- (void)setModel:(GSSubscrebe_Add_Topic *)model{
    _model = model;
// 各个控件赋值
    //如果是  从数据库里拿出来的,就可以直接赋值了
    if (model.imageModel) {
        _imageV.image = model.imageModel;
    }else{
    // 图片
    [_imageV sd_setImageWithURL:[NSURL URLWithString:model.thumbnailUrl] placeholderImage:nil];
    }
    // 标题
    _titleLabel.text = model.sourceName;
    // 订阅人数
    _subscibeCount.text = [NSString stringWithFormat:@"%@人订阅",model.cnt];
    // 判断  model的属性, 来 确定 订阅按钮的样式
    if (model.isSubscribe) {
        _subscibeButton.selected = YES;
        _subscibeButton.backgroundColor = [UIColor grayColor];
    }else{
        _subscibeButton.selected = NO;
        _subscibeButton.backgroundColor = [UIColor redColor];
    }
}

- (void)setSearchModel:(GSSearch_Model *)searchModel{
    _searchModel = searchModel;
// 各个控件赋值
    [_imageV sd_setImageWithURL:[NSURL URLWithString:searchModel.thumbnailURLs[0]] placeholderImage:nil];
    _titleLabel.text = searchModel.title;
    _subscibeCount.text = [NSString stringWithFormat:@"%@人订阅",searchModel.readingCount];
    
    // 判断 model的属性  确定订阅按钮的样式
    if (searchModel.isSubscribe) {
        _subscibeButton.selected = YES;
        _subscibeButton.backgroundColor = [UIColor grayColor];
    }else{
        _subscibeButton.selected = NO;
        _subscibeButton.backgroundColor = [UIColor redColor];
    }
}
#pragma mark---------------------------------------------
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
